class Solution {
public:
    int subarraysDivByK(vector<int>& nums, int k) {
        int sum = 0;
        unordered_map<int,int> hash;
        int ret = 0;
        hash[0] = 1;
        for(auto& x:nums)
        {
            sum+=x;
            if(hash.count((sum%k+k)%k))
                ret+=hash[(sum%k+k)%k];
            hash[sum]++;
        }
        return ret;
    }
};